package com.xinxin.leetcode.problem141;

import com.xinxin.leetcode.common.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 史鑫鑫
 * @date 2019-08-26 2:23
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        Set<ListNode> node = new HashSet<>();
        while(head!=null)
        {
            if(node.contains(head)) {
                return true;
            } else {
                node.add(head);
            }
            head = head.next;
        }
        return false;
    }
}
